215fa6ce54814db5de189dabb658db20fd4f8499,src/java/grails/orm/HibernateCriteriaBuilder.java,HibernateCriteriaBuilder,invokeMethod,#String#Object#,960
Before Change
for(Iterator<Order> it = orderEntries.iterator();it.hasNext();){
this.criteria.addOrder(it.next());
}
this.criteria.setResultTransformer(CriteriaSpecification.ROOT_ENTITY);
GrailsHibernateUtil.populateArgumentsForCriteria(targetClass, this.criteria, (Map)args[0]);
PagedResultList pagedRes = new PagedResultList(this.criteria.list());
After Change
public Object invokeMethod(String name, Object obj) {
Object[] args = obj.getClass().isArray() ? (Object[])obj : new Object[]{obj};
if(paginationEnabledList && SET_RESULT_TRANSFORMER_CALL.equals(name) && args.length == 1 && args[0] instanceof ResultTransformer) {
resultTransformer = (ResultTransformer) args[0];
return null;
}
if(isCriteriaConstructionMethod(name, args)) {
if(this.criteria != null) {
throwRuntimeException( new IllegalArgumentException("call to [" + name + "] not supported here"));
}
if (name.equals(GET_CALL)) {
this.uniqueResult = true;
}
else if (name.equals(SCROLL_CALL)) {
this.scroll = true;
}
else if (name.equals(COUNT_CALL)) {
this.count = true;
}
else if (name.equals(LIST_DISTINCT_CALL)) {
this.resultTransformer = CriteriaSpecification.DISTINCT_ROOT_ENTITY;
}
createCriteriaInstance();
// Check for pagination params
if(name.equals(LIST_CALL) && args.length == 2) {
paginationEnabledList = true;
orderEntries = new ArrayList<Order>();
invokeClosureNode(args[1]);
} else {
invokeClosureNode(args[0]);
}
if(resultTransformer != null) {
this.criteria.setResultTransformer(resultTransformer);
}
Object result;
if(!uniqueResult) {
if(scroll) {
result = this.criteria.scroll();
}
else if(count) {
this.criteria.setProjection(Projections.rowCount());
result = this.criteria.uniqueResult();
} else if(paginationEnabledList) {
// Calculate how many results there are in total. This has been
// moved to before the 'list()' invocation to avoid any "ORDER
// BY" clause added by 'populateArgumentsForCriteria()', otherwise
// an exception is thrown for non-string sort fields (GRAILS-2690).
this.criteria.setFirstResult(0);
this.criteria.setMaxResults(Integer.MAX_VALUE);
this.criteria.setProjection(Projections.rowCount());
int totalCount = ((Integer)this.criteria.uniqueResult()).intValue();
// Drop the projection, add settings for the pagination parameters,
// and then execute the query.
this.criteria.setProjection(null);
for(Iterator<Order> it = orderEntries.iterator();it.hasNext();){
this.criteria.addOrder(it.next());
}
if(resultTransformer == null) {
this.criteria.setResultTransformer(CriteriaSpecification.ROOT_ENTITY);
} else if(paginationEnabledList) {
// relevant to GRAILS-5692
this.criteria.setResultTransformer(resultTransformer);